package org.anachronos.jeep.ui.trace;

import org.anachronos.jeep.core.agent.ProfilerRemoteControl;
import org.anachronos.jeep.core.attach.VirtualMachineAttachement;
import org.anachronos.jeep.core.attach.VirtualMachineAttachement.State;
import org.anachronos.jeep.ui.attach.VirtualMachineAttachementCommand;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

public class StartProfilingCommand extends VirtualMachineAttachementCommand {

	@Override
	public Object execute(final ExecutionEvent event) throws ExecutionException {
		try {
			final ProfilerRemoteControl profilerRemoteControl = 
				getProfilerRemoteControl(event);
			profilerRemoteControl.startProfiling();
			final VirtualMachineAttachement virtualMachineAttachement = 
				getSelection(event);
			virtualMachineAttachement.setState(State.PROFILING);
		} catch (final Exception e) {
			throw new ExecutionException("", e);
		}
		return null;
	}
}
